package com.toggery.POS.service;

import com.toggery.POS.dao.OrderdetailMapper;
import com.toggery.POS.entity.OrderdetailRecord;
import com.toggery.POS.entity.Orderdetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderDetailService {
    @Autowired
    OrderdetailMapper mapper;

    public List<Orderdetail> findAll(){
        return  mapper.findAll();
    }
    public List<Orderdetail> findAllWithOrderId(int orderId){
        return  mapper.findAllWithinOrder(orderId);
    }
    public boolean save(Orderdetail order){
        if(mapper.selectByPrimaryKey(order.getId())==null){
            mapper.insert(order);
            return true;
        }else {
            return false;
        }
    }

    public boolean updateOrder(Orderdetail order){
        if(mapper.updateByPrimaryKey(order)>0){
            return true;
        }else {
            return false;
        }
    }
    public boolean deleteByid(int id){
        if(mapper.deleteByPrimaryKey(id)>0){
            return true;
        }else {
            return false;
        }
    }
    public Orderdetail findById(int id){
        return mapper.selectByPrimaryKey(id);
    }


//    public List<Order> findAllWithin() {
//        return mapper.findAll();
//    }
}
